package demo;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;

import util.IpUtils;

/**
 * Hello world!
 *
 */
public class App {
	public static void main(String[] args) {
		App a = new App();
		List<String> urlList = CommParam.urlList;
		for (int i = 0; i < urlList.size(); i++) {
			a.start(urlList.get(i));
			System.out.println("===============================");
		}
	}

	public void start(String url) {
		System.out.println("抓取网址：" + url);
		String ip = getIP(url);
		System.out.println("ip：" + ip);
		IpUtils ipUtils = new IpUtils();
		// 对应省份
		String ipAddr = Arrays.toString(ipUtils.getLocationFromTaobao(ip));
		System.out.println("对应省份：" + ipAddr);
	}

	public static String getIP(String name) {
		InetAddress address = null;
		try {
			address = InetAddress.getByName(name);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("获取失败");
		}
		return address.getHostAddress().toString();
	}
}
